<?php

require_once('database.php');

define('USER_HOME_DIR', dirname('header.php'));

define('SERIAL', 1);

require_once("smarty/Smarty.class.php");

$smarty = new Smarty();
//configure Smarty
$smarty->template_dir = USER_HOME_DIR . "/template";
$smarty->compile_dir = USER_HOME_DIR . "/template_c";
$smarty->cache_dir = USER_HOME_DIR . "/cache";
$smarty->config_dir = USER_HOME_DIR . "/config";

session_start();


$db = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PW);










function getTopicListCode() {

	global $db;
	
	$code = '';

	foreach( $db->query('Select * From topic Where serial_id='.SERIAL) as $row ) {
		$code .= '<li><a href="./?topic=' . $row['topic_id'] . '">' . htmlspecialchars($row['name']) . '</a></li>';
	}

	return $code;

}

function getTopicOptionCode() {

	global $db;
	
	$code = '';

	foreach( $db->query('Select * From topic Where serial_id='.SERIAL) as $row ) {
		$code .= '<option value="' . $row['topic_id'] . '">' . htmlspecialchars($row['name']) . '</option>';
	}

	return $code;

}

function getCountryListCode() {

	global $db;
	
	// default == "Australia" == 12
	$id = 12;
	
	$code = '';

	foreach( $db->query('Select * From countries') as $row ) {
		$code .= '<option value="' . $row['country_id'] . '"' . ($row['country_id']==$id ? ' selected="selected"' : '') . '>' . htmlspecialchars($row['country_name']) . '</option>';
	}

	return $code;

}


?>